SPQR: build factors with typed constructors, for type-stability - #756
Open
topolarity wants to merge 2 commits into
Open
SPQR: build factors with typed constructors, for type-stability#756topolarity wants to merge 2 commits into
topolarity wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #756 +/- ##
==========================================
- Coverage 84.08% 83.99% -0.09%
==========================================
Files 13 13
Lines 9367 9367
==========================================
- Hits 7876 7868 -8
- Misses 1491 1499 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Wait, why does the function accept |
SPQR only computes in double precision: its C entry points instantiate the `double` templates and never inspect the matrix `dtype`. Since single precision support was added, `qr` passed `Float32` and `ComplexF32` matrices through as single-precision CHOLMOD matrices, which SPQR then read as doubles and returned garbage factors for (a `Float32` diagonal of 1, 2, 3 came back as `R = [2.0000005 0 0; 0 0 0; 0 0 0]`). The regression test only compared element types, so this went unnoticed. Restrict the SPQR method to `Float64` and `ComplexF64`, and route the narrower real and complex types through an explicit conversion to double precision, converting the factors back afterwards, as was already done for `Float16`. The converted methods also accept `ordering`, as the double methods do. This commit was written with the assistance of generative AI (Claude). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`qr` wrapped SPQR's result pointers with the untyped `Sparse(ptr)` and `Dense(ptr)` constructors, which read the element type from the C struct and so dispatch dynamically. SPQR is only ever handed double precision input now and returns factors of the same type, so use the typed constructors, which also check that the returned `xtype` and `dtype` are the expected ones. This commit was written with the assistance of generative AI (Claude). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
topolarity
force-pushed
the
ct/trim-spqr
branch
from
September 3, 2026 16:50
1eeb4b4 to
ed2e55a
Compare
Contributor
Author
|
You're right. This is broken right now: julia> qr(SparseMatrixCSC{Float32}(sparse([1,2,3],[1,2,3],[1.0,2.0,3.0]))).R
3×3 SparseMatrixCSC{Float32, Int64} with 1 stored entry:
2.0 ⋅ ⋅
⋅ ⋅ ⋅
⋅ ⋅ ⋅
julia> qr(SparseMatrixCSC{Float64}(sparse([1,2,3],[1,2,3],[1.0,2.0,3.0]))).R
3×3 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
1.0 ⋅ ⋅
⋅ 2.0 ⋅
⋅ ⋅ 3.0I have pushed a quick fix to the branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last PR of the
--trimset!Having the types spelled out explicitly here allows these constructors to be fully inferred w.r.t. dispatch. This does not affect the return type of any call, so no
@inferredtest is included.This commit was written with the assistance of generative AI (Claude) 🤖